#!/bin/bash
if(test -L $0) then
    	auxlink=`ls -l $0 | sed 's/^[^>]*-> //g'`
    	M_HOME=`dirname $auxlink`/
else 
    	M_HOME=`dirname $0`/
fi
cd $M_HOME

PACKAGE_DIR=$PWD/package
PATCH_DIR=$PWD/patch
export BUILD_DIR=$PWD/build
export STATIC_LIB_DIR=/opt/9263/staticlibs
export TOOLCHAIN_DIR=/opt/9263/toolchain
export SOURCE_DIR=$PWD/source
export TARGET=arm-none-linux-gnueabi

export HOST=`gcc -dumpmachine`
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export CONFIG_SHELL=/bin/bash

# check directory exists
[ -d $PACKAGE_DIR -a -d $BUILD_DIR -a -d $PATCH_DIR -a -d $SOURCE_DIR -a -d /opt/9263 ]
if [ $? -ne 0 ] ; then
	echo 'one of the following does not exist: '
	echo $PACKAGE_DIR
	echo $BUILD_DIR
	echo $PATCH_DIR
	echo $SOURCE_DIR
	echo /opt/9263
	exit 1
fi

$PACKAGE_DIR/download .pkglist || exit 1
$PATCH_DIR/download .patchlist || exit 1
$SOURCE_DIR/unpackAndPatch .pkglist .patchlist || exit 1
./dirvar .pkglist > .varlist || exit 1
rm .pkglist .patchlist -f

unset CFLAGS CXXFLAGS
if [ `uname -m` == x86_64 ]; then export LIB_CFLAGS="-fPIC"; fi

./kernelheader || exit 1
./staticlibs || exit 1
./binutils || exit 1
./gcc1 || exit 1
./glibc || exit 1
./gcc2 || exit 1
./link || exit 1

rm .varlist -f
